package com.wfh.controller;

import com.wfh.common.BaseResponse;
import com.wfh.common.ResultUtils;
import com.wfh.model.entity.Blog;
import com.wfh.model.vo.BlogVO;
import com.wfh.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author FengHuan Wang
 * @Date 2025/4/18 18:36
 * @Version 1.0
 */
@RestController
@RequestMapping("blog")
public class BlogController {

    @Resource
    private BlogService blogService;

    /**
     * 根据id获取博客接口
     * @param blogId
     * @param request
     * @return
     */
    @GetMapping("/get")
    public BaseResponse<BlogVO> get(Long blogId, HttpServletRequest request){
        BlogVO blogVO = blogService.getBlogVOById(blogId, request);
        return ResultUtils.success(blogVO);
    }

    /**
     * 批量查询博客接口
     * @param request
     * @return
     */
    @GetMapping("/list")
    public BaseResponse<List<BlogVO>> list(HttpServletRequest request){
        List<Blog> blogList = blogService.list();
        List<BlogVO> blogVOList = blogService.getBlogVOList(blogList, request);
        return ResultUtils.success(blogVOList);
    }
}
